﻿Imports CreativeImagesByKim
Imports System.Net
Imports System.Net.Mail
Imports System.Web.Services
Imports System.Text

Namespace Pages
    Public Class ContactPage
        Inherits System.Web.UI.Page

    #Region "Private Members"
        Private _MasterPage As CIMasterPage
    #End Region

    #Region "Page Methods"
        Protected Sub Page_Load(ByVal sender As Object, 
                                ByVal e As EventArgs) _
            Handles Me.Load

            ' Get the master page
            Me._MasterPage = DirectCast(Me.Master, CIMasterPage)
        End Sub
    #End Region

    #Region "Private Shared Methods"
        Private Shared Function SendClientMessage(ByVal clientName As String,
                                                  ByVal clientEmail As String,
                                                  ByVal clientMessage As String) As Boolean
            Dim didSendClientMessage As Boolean = True
            Dim smtpClient As SmtpClient = New SmtpClient("mail.creativeimagesbykim.com", 26)
            smtpClient.Credentials = New NetworkCredential("contact@creativeimagesbykim.com", "athlon2500")

            Dim messageBodyBuilder As New StringBuilder()
            messageBodyBuilder.Append("Kim,")
            messageBodyBuilder.Append("<br /><br />")
            messageBodyBuilder.Append(String.Format("<b>{0}</b> has sent you a message via your contact page! ", clientName))
            messageBodyBuilder.Append(String.Format("They may be contacted at: <b>{0}</b>.", clientEmail))
            messageBodyBuilder.Append("<br /><br />")
            messageBodyBuilder.Append(String.Format("<b>{0}'s</b> message:", clientName))
            messageBodyBuilder.Append("<br />" & "<i>" & clientMessage & "</i>")

            Dim email As New MailMessage()
            email.From = New MailAddress("contact@creativeimagesbykim.com")
            email.To.Add(New MailAddress("kim@creativeimagesbykim.com"))
            email.Bcc.Add(New MailAddress("jeremy@creativeimagesbykim.com"))
            email.Subject = String.Format("New message from {0}!", clientName)
            email.Body = messageBodyBuilder.ToString()
            email.IsBodyHtml = True

            Try
                smtpClient.Send(email)
            Catch ex As Exception
                didSendClientMessage = False
            End Try

            Return didSendClientMessage
        End Function
    #End Region

    #Region "Web Methods"
        <WebMethod()>
        Public Shared Function SubmitClientMessage(ByVal clientName As String,
                                                   ByVal clientEmail As String,
                                                   ByVal clientMessage As String) As Boolean
            Return SendClientMessage(clientName, clientEmail, clientMessage)
        End Function
    #End Region
    End Class
End Namespace